// 6. 定义页面
import 'package:flutter/material.dart';
import 'package:t_flutter_test/component/layout_widget.dart';
import 'package:t_flutter_test/router/index.dart' show RouterInfo, allRouter;

class IndexPage extends StatefulWidget {
  const IndexPage({super.key});

  @override
  IndexPageState createState() => IndexPageState();
}

class IndexPageState extends State<IndexPage> {
  List<RouterInfo> showRouterList = allRouter.sublist(1);

  @override
  Widget build(BuildContext context) {
    return LayoutWidget(
      isFirst: true,
      body: ListView.builder(
        itemBuilder: (context, index) {
          return GestureDetector(
            onTap: () {
              RouterInfo routerInfo = showRouterList[index];
              // 命名路由跳转
              Navigator.pushNamed(
                context,
                routerInfo.path,
                // 此处的 appBarTitle 用于 LayoutWidget 组件显示当前页面的名称(AppBar.title)
                arguments: {'appBarTitle': routerInfo.name},
              );
            },
            child: Container(
              margin: EdgeInsets.only(top: 10, left: 10, right: 10),
              child: Text(
                '${index + 1}. ${showRouterList[index].name}',
                style: TextStyle(fontSize: 20, color: Colors.deepOrange),
              ),
            ),
          );
        },
        itemCount: showRouterList.length,
      ),
    );
  }
}
